home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / raytrace / renaisnc / lib.lha / Lib / tree.h < prev   
Encoding:
C/C++ Source or Header  |  1992-01-04  |  3.7 KB  |  118 lines

  1. /*
  2. **  File:  tree.h
  3. **  Author:  Karen Foltz
  4. **  Created: 10 Oct 1986
  5. **  Purpose:
  6. **      The module "tree" contains the definition of the binary tree data
  7. **    structure used by the Constructive Solid Geometry modelling system 
  8. **    to describe an object.  
  9. **    A set of operations to help build these trees representing objects
  10. **    is also provided.
  11. */
  12. #include "boundingvol.h"
  13.  
  14. /*
  15. ** Definition of the Primitive objects:
  16. **
  17. ** Sphere is of unit radius centered at the origin.
  18. ** Cube has sides of length 2 and is centered at the origin.
  19. ** Cone has height 1, radius 1 and the center of the base is at the origin.
  20. ** Cylinder has height 2, radius one and is centered at the origin.
  21. ** HalfSpace is defined by  z<=0.
  22. ** Torus is centered at the origin.  It's cross-section in the YZ
  23. **   plane is a circle of radius r centered at [0,1,0].
  24. **   r is a parameter taken from surface.parms.r.
  25. **   The torus is formed by rotating this cross-section around the Z axis.
  26. ** Mesh is a subdivision surface of user design.
  27. */
  28.  
  29. typedef enum PrimitiveObjects {Sphere,Cube,Cone,Cylinder,HalfSpace,Torus,MeshP};
  30. typedef enum NodeTypes { Primitive, Composite };
  31. typedef enum OpCodes { Union, Intersect, Difference };
  32.  
  33. typedef struct {    /* A primitive object description */
  34.         enum PrimitiveObjects shape;
  35.     char *param;  /* Pointer to object parameters */
  36. } PrimitiveShape;
  37.  
  38. /* Surface and Material descriptions */
  39.  
  40. /* descriptions of surfaces and texture models */
  41. typedef struct {
  42.     struct token *texture;        /* pointer to interpreter texture function */
  43.     int emitter;                  /* =TRUE if fun returns emitting surfaces  */
  44.     int hollow;                   /* =TRUE if primitive is surface not solid */
  45.     TransformType4D embedding;    /* embedding from view to texture space    */
  46.     TransformType4D inv_embedding;/* inverse of embedding                    */
  47.   } MaterialDescr;
  48.  
  49.  
  50. /*
  51. ** NOTE:  Embedding matrices are originally between local coordinates
  52. **        and the parent nodes coordinate system.  The procedure
  53. **        InitializeScene in module scene changes these tranforms to
  54. **        between local and view coordinates.
  55. */
  56.  
  57. typedef struct ctree{   /* a node in the tree */
  58.     enum NodeTypes  kind;          /* primitive or composite */
  59.     TransformType4D embedding;     /* the embedding matrix */
  60.     TransformType4D invembedding;  /* its inverse */
  61.     BoundingVolume  bound_volume;  /* a bounding sphere */
  62.     union {
  63.         struct {   /* info for a primitive node */
  64.             PrimitiveShape  shape;   /* the primitive shape*/
  65.             MaterialDescr   surface; /* surface characteristics */
  66.             double r;                /* Torus radius */
  67.         } p;
  68.         struct {   /* info for a composite node */
  69.             enum OpCodes     operation;
  70.             struct ctree *l_solid_ptr;
  71.             struct ctree *r_solid_ptr;
  72.         } c;
  73.     } var;
  74. } CSGtree;
  75.  
  76. /*
  77. ** MakeCompositeNode(op,l_solid,r_solid,embed,invembed)  makes a new
  78. ** internal node and returns a pointer to it.
  79. */
  80. extern CSGtree *MakeCompositeNode();
  81.  
  82. /*
  83. ** MakePrimitiveNode(shape, embed, invembed, surface)  
  84. ** Makes a new leaf node and  returns a pointer to it.
  85. */
  86. extern CSGtree *MakePrimitiveNode();
  87.  
  88. /*
  89. ** EmbedNode(node, embed, invembed)  
  90. ** Pre-multiply the current embedding matrix of node by new additional
  91. **  embedding.
  92. */
  93. extern CSGtree *EmbedNode();
  94.  
  95. /*
  96. ** DuplicateTree(tree)  make a duplicate of the structure tree and 
  97. ** return a pointer to it.
  98. */
  99. extern CSGtree *DuplicateTree();
  100.  
  101. /*
  102. ** SetSurface(node,surface), CSGtree *node; MaterialDescr surface; 
  103. ** set the surface description associated with node.
  104. */
  105. extern CSGtree *SetSurface();
  106.  
  107. /*
  108. ** PrintCSGtree(ptr)  recursively writes the contents of the tree to 
  109. ** stdout.
  110. */
  111. extern void PrintCSGtree();
  112.  
  113. extern void PrintOpcode();
  114. extern void PrintPrimitiveObject();
  115. extern void PrintNodeType();
  116. extern void PrintMaterial();
  117. extern void PrintBoundVolume();
  118.